#!/bin/bash

export logfile="test_result.txt"
export datadir="../../data"
export driver=`vainfo 2>&1|grep "Trying to open"|awk -F '/' '{print $NF}'`

if [ -z $driver ];then
    echo "Please install vainfo at first"
    exit 0
fi

rm $logfile -f
cd src/exec

fps=`./videodecode -t hwdec -p vaapi -c $datadir/H264_3840X2160.mp4 |grep "decode fps"|awk '{print $4}'`
echo "h264 vaapi decoding fps: $fps" >> ../$logfile
fps=`./videodecode -t hwdec -p vdpau -c $datadir/H264_3840X2160.mp4 |grep "decode fps"|awk '{print $4}'`
echo "h264 vdpau decoding fps: $fps" >> ../$logfile
fps=`./videodecode -t hwdec -p vaapi -c $datadir/HEVC_3840x2160.mp4 |grep "decode fps"|awk '{print $4}'`
echo "hevc vaapi decoding fps: $fps" >> ../$logfile
fps=`./videodecode -t hwdec -p vdpau -c $datadir/HEVC_3840x2160.mp4 |grep "decode fps"|awk '{print $4}'`
echo "hevc vdpau decoding fps: $fps" >> ../$logfile
#fps=`./videodecode -t hwdec -p vaapi -c $datadir/MPEG2_3840x2160.mp4 |grep "decode fps"|awk '{print $4}'`
#echo "mpeg2 vaapi decoding fps: $fps" >> ../$logfile
#fps=`./videodecode -t hwdec -p vdpau -c $datadir/MPEG2_3840x2160.mp4 |grep "decode fps"|awk '{print $4}'`
#echo "mpeg2 vdpau decoding fps: $fps" >> ../$logfile

case "$driver" in
    "arise_drv_video.so" )
        score=`./videodecode -t hwencode -c $datadir/ParkScene_1920x1080_24_yuy2_1.yuv -s 1920x1080 -n h264_vaapi -f yuyv|grep "score for"|awk '{print $5}'`
        echo "h264 encoding score: $score" >> ../$logfile
        score=`./videodecode -t hwencode -c $datadir/ParkScene_1920x1080_24_yuy2_1.yuv -s 1920x1080 -n hevc_vaapi -f yuyv|grep "score for"|awk '{print $5}'`
        echo "hevc encoding score: $score" >> ../$logfile;;
    * )
        score=`./videodecode -t hwencode -c $datadir/ParkScene_1920x1080_24_i420_1.yuv -s 1920x1080 -n h264_vaapi -f i420|grep "score for"|awk '{print $5}'`
        echo "h264 encoding score: $score" >> ../$logfile
        score=`./videodecode -t hwencode -c $datadir/ParkScene_1920x1080_24_i420_1.yuv -s 1920x1080 -n hevc_vaapi -f i420|grep "score for"|awk '{print $5}'`
        echo "hevc encoding score: $score" >> ../$logfile;;
esac

cd -
